package demo;

import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.util.List;

import lib.OneMenuHasClickFilter;
import lib.OneMenuNoClickFilter;
import lib.TwoMenuFilter;
import lib.WebFilter;

import pojo.Website;

import dao.LinkDAO;
import dao.WebsiteDAO;

public class getlink {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		WebsiteDAO dao = new WebsiteDAO();
		
		List<Website> list= dao.getList();
		List<String> name;
		List<String> link;

		LinkDAO linkDAO= new LinkDAO();
		for(int i= 4;i<list.size();i++)
		{
			Website web= list.get(i);
			System.out.println(web.getWebsite());
			if(web.getWebType().equals("1"))
			{
				OneMenuNoClickFilter fil= new OneMenuNoClickFilter();
				fil.lay_noi_dung_web(web.getWebsite(),web.getMenu1(), web.getMenu2());
				name= fil.getTopicDic();
				link=fil.getLink();
			}
			else
				if(web.getWebType().equals("2"))
				{
					OneMenuHasClickFilter fil= new OneMenuHasClickFilter();
					fil.lay_noi_dung_web(web.getWebsite(),web.getMenu1(), web.getMenu2());
					name= fil.getTopicDic();
					link=fil.getLink();
				}
				else
				{
					TwoMenuFilter fil= new TwoMenuFilter();
					fil.lay_noi_dung_web3(web.getWebsite(),web.getMenu1(), web.getMenu2());
					name= fil.getTopicDic();
					link=fil.getLink();
				}
			

			System.out.println(i);
			for(int j= 0;j<name.size();j++)
			{	
				System.out.print("a");
				System.out.print(j);
				linkDAO.insert(web.getWebsiteId(), 0,link.get(j) ,name.get(j));
				Writer out1;
				try {
					out1 = new BufferedWriter(new OutputStreamWriter(
							new FileOutputStream("E:\\vina.txt",true),"UTF-8"));
					out1.write(name.get(j));
					out1.write(System.getProperty( "line.separator" ));
					out1.write(link.get(j));
					out1.write(System.getProperty( "line.separator" ));
					out1.write(System.getProperty( "line.separator" ));
					out1.close();
				} catch (UnsupportedEncodingException | FileNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
					
				
			}
			System.out.println();

		}
	}

}
